<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue使用之动态组件</title>
    <script src="../vue.min.js" type="text/javascript"></script>
</head>
<body>
<div id="app">
    <keep-alive>
        <component :is="sex"></component>
    </keep-alive>
    <button @click="change">切换</button>
</div>

<script type="text/javascript">
    Vue.component('boy',{
        template:`
            <div>
                boy:<input type="text" />
            </div>
        `
    })
    Vue.component('girl',{
        template:`
            <div>
                girl:<input type="text" />
            </div>
        `
    })
    var app=new Vue({
        el: '#app',
        data:{
            sex: 'boy'
        },
        methods:{
            change:function () {
                this.sex = this.sex==='boy' ? 'girl': 'boy'
            }
        }
    })
</script>
</body>
</html>